﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace chess
{
    public class csFig
    {

        private enumFigType _fType;
        private int _posSpalte = 0;
        private int _posZeile = 0;
        private enumFigParty _fParty;
        private int _value = 0;
        private csMoves _move = null;
        private csBoard _csBoard = null;
        private enumFigStatus _status = enumFigStatus.active;
        private bool _ersterZugGemacht = false;
        private bool _enPassant = false;
        private bool _marked = false;

        public csFig(csBoard board, enumFigType fType, enumFigParty party, int spalte, int zeile)
        {
            this._posSpalte = spalte;
            this._posZeile = zeile;
            this._fType = fType;
            this._fParty = party;
            this._csBoard = board;

            this._value = ((int)this._fType + 1);

            switch (fType)
            {
                case enumFigType.B:
                    this._move = new csMoves(Tools.bMove);
                    break;
                case enumFigType.T:
                    this._move = new csMoves(Tools.tMove);
                    // Wenn die Figur kein Bauer ist, ist der erste Zug sowieso irrelevant
                    this.ErsterZugGemacht = true;
                    break;
                case enumFigType.L:
                    this._move = new csMoves(Tools.lMove);
                    // Wenn die Figur kein Bauer ist, ist der erste Zug sowieso irrelevant
                    this.ErsterZugGemacht = true;
                    break;
                case enumFigType.S:
                    this._move = new csMoves(Tools.sMove);
                    // Wenn die Figur kein Bauer ist, ist der erste Zug sowieso irrelevant
                    this.ErsterZugGemacht = true;
                    break;
                case enumFigType.D:
                    this._move = new csMoves(Tools.dMove);
                    // Wenn die Figur kein Bauer ist, ist der erste Zug sowieso irrelevant
                    this.ErsterZugGemacht = true;
                    break;
                case enumFigType.K:
                    this._move = new csMoves(Tools.kMove);
                    // Wenn die Figur kein Bauer ist, ist der erste Zug sowieso irrelevant
                    this.ErsterZugGemacht = true;
                    break;
                default:
                    break;
            }
        }

        public csFig(csBoard board, string fType, string party, int spalte, int zeile)
        {
            try {
                this._posSpalte = spalte;
                this._posZeile = zeile;

                switch (fType.ToUpper())
                {
                    case "B":
                        this._fType = enumFigType.B;
                        this._move = new csMoves(Tools.bMove);
                        break;
                    case "D":
                        this._fType = enumFigType.D;
                        this._move = new csMoves(Tools.dMove);
                        break;
                    case "K":
                        this._fType = enumFigType.K;
                        this._move = new csMoves(Tools.kMove);
                        break;
                    case "L":
                        this._fType = enumFigType.L;
                        this._move = new csMoves(Tools.lMove);
                        break;
                    case "S":
                        this._fType = enumFigType.S;
                        this._move = new csMoves(Tools.sMove);
                        break;
                    case "T":
                        this._fType = enumFigType.T;
                        this._move = new csMoves(Tools.tMove);
                        break;
                    default:
                        break;
                }

                switch (party)
                {
                    case "B":
                        this._fParty = enumFigParty.Black;
                        break;
                    case "W":
                        this._fParty = enumFigParty.White;
                        break;
                    default:
                        break;
                }

                this._csBoard = board;

                this._value = ((int)this._fType + 1);
            } catch(Exception e)
            {
                return;
            }
        }

        public bool Marked
        {
            get { return this._marked; }
            set { this._marked = value; }
        }

        public bool EnPassantGeradeAusgefuehrt
        {
            get { return this._enPassant;  }
            set { this._enPassant = value; }
        }

        public enumFigStatus Status
        {
            get
            {
                return this._status;
            }
            set
            {
                this._status = value;
            }
        }

        public enumFigType FigType
        {
            get { return this._fType; }
            set { this._fType = value; }
        }

        public int Spalte
        {
            get { return this._posSpalte; }
        }

        public int Zeile
        {
            get { return this._posZeile; }
        }

        public int Value
        {
            get { return this._value; }
        }

        public enumFigParty Party
        {
            get { return this._fParty; }
        }

        public string getDescription
        {
            get
            {
                string strCol = Tools.columnTranslation[this.Spalte];
                return this._fParty.ToString() + this._fType.ToString() + strCol + Convert.ToString(8 - this.Zeile);
            }
        }
        
        public List<csField> evaluateMoves(enumFieldMarkerType marker)
        {
            List<csField> csFields = this._move.Evaluate(this, this._csBoard, marker);
            return csFields;
        }

        public void SetField(int spalte, int zeile)
        {
            this._posSpalte = spalte;
            this._posZeile = zeile;
        }

        public bool ErsterZugGemacht
        {
            get { return _ersterZugGemacht; }
            set { _ersterZugGemacht = value; }
        }
        
    }
}
